package com.shelpe.services.sustainer.ranking;

import org.springframework.batch.item.ItemProcessor;

import com.shelpe.services.sustainer.client.RankingClient;
import com.shelpe.services.sustainer.entity.jpa.Tactics;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Setter
public class ExecuteRankingProcessor implements ItemProcessor<Tactics, TacticsResult> {

	private RankingClient rankingClient;
	
	@Override
	public TacticsResult process(Tactics t) throws Exception {
		log.debug("ExecuteRanking[{}]: {}", t.getTacticsID(), t);
		TacticsResult res = new TacticsResult();
		res.setTactics(t);
		
		RankingClient.RankingRes rankingRes = this.rankingClient.executeRanking(t.getTacticsID());
		if(!rankingRes.isStatus()){
			log.error("fail to start auto drive: {}", t);
		}
		res.setStatus(rankingRes.isStatus()?1:-1);
		return res;
	}

}
